home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / helpful.zip / printuse < prev    next >
Text File  |  1995-08-21  |  16KB  |  501 lines

  1.   The Linux Printing Usage HOWTO
  2.   by Matt Foster  <mwf@engr.uark.edu>
  3.   v1.0, 5 Aug 1995
  4.  
  5.   1.  Introduction
  6.  
  7.   This document describes how to use the line printer spooling system
  8.   provided with the Linux operating system.  If you are looking for a
  9.   guide to setting up your print environment, please see the Linux
  10.   Printing Setup HOWTO.
  11.  
  12.  
  13.   1.1.  Linux Printing HOWTO History
  14.  
  15.   This version of the Linux Printing HOWTO is a complete rewrite of the
  16.   one originally written by Grant Taylor <grant@god.tufts.edu> and Brian
  17.   McCauley <B.A.McCauley@bham.ac.uk>.  I have tried to keep with the
  18.   coverage of material presented by Grant and Brian's HOWTO, but I have
  19.   drastically modified the style of presentation and the depth of
  20.   material covered.  I feel that this makes the HOWTO more complete and
  21.   easier to read.  I can only hope that you agree.
  22.  
  23.  
  24.   1.2.  Copyrights and Trademarks
  25.  
  26.   Some names mentioned in this HOWTO are claimed as copyrights and/or
  27.   trademarks of certain persons and/or companies.  These names appear in
  28.   full or initial caps in this HOWTO.
  29.  
  30.  
  31.   The Linux Printing Usage HOWTO v1.0 (c) 1995 Matt Foster.
  32.  
  33.  
  34.   Unless otherwise stated, Linux HOWTO documents are copyrighted by
  35.   their respective authors. Linux HOWTO documents may be reproduced and
  36.   distributed in whole or in part, in any medium physical or electronic,
  37.   as long as this copyright notice is retained on all copies. Commercial
  38.   redistribution is allowed and encouraged; however, the author would
  39.   like to be notified of any such distributions.
  40.  
  41.   All translations, derivative works, or aggregate works incorporating
  42.   any Linux HOWTO documents must be covered under this copyright notice.
  43.   That is, you may not produce a derivative work from a HOWTO and impose
  44.   additional restrictions on its distribution. Exceptions to these rules
  45.   may be granted under certain conditions; please contact the Linux
  46.   HOWTO coordinator at the address given below.
  47.  
  48.   In short, we wish to promote dissemination of this information through
  49.   as many channels as possible. However, we do wish to retain copyright
  50.   on the HOWTO documents, and would like to be notified of any plans to
  51.   redistribute the HOWTOs.
  52.  
  53.   If you have questions, please contact Greg Hankins, the Linux HOWTO
  54.   coordinator, at <gregh@sunsite.unc.edu>. You may finger this address
  55.   for phone number and additional contact information.
  56.  
  57.  
  58.   1.3.  Downloading the Linux Printing HOWTOs
  59.  
  60.   I recommend that if you want to print a copy of this HOWTO that you
  61.   download the PostScript version.  It is formatted in a fashion that is
  62.   aesthetically appealing and easier to read.  You can get the
  63.   PostScript version from one of the many Linux distribution sites (such
  64.   as SunSITE <ftp://sunsite.unc.edu/Linux/docs/HOWTO/>), or directly
  65.   from my World Wide Web page at  <http://www.engr.uark.edu/~mwf/pht/>.
  66.  
  67.   1.4.  Feedback
  68.  
  69.   Questions, comments, or corrections for this HOWTO may be directed to
  70.   <mwf@engr.uark.edu>.
  71.  
  72.  
  73.   1.5.  Acknowledgments
  74.  
  75.   Thanks go out to all of the people who took the time to read the alpha
  76.   version of this HOWTO and respond with many helpful comments and
  77.   suggestions--some of you may see your comments reflected in the
  78.   version.
  79.  
  80.   I would also like to thank Grant and Brian for the loads of
  81.   information that they have given me during the transition of
  82.   authorship.
  83.  
  84.  
  85.   2.  Printing Under Linux
  86.  
  87.   This section discusses how to print files, examine the print queue,
  88.   remove jobs from the print queue, format files before printing them,
  89.   and configure your printing environment.
  90.  
  91.  
  92.   2.1.  History
  93.  
  94.   The Linux printing system---the lp system---is a port of the source
  95.   code written by the Regents of the University of California for the
  96.   Berkeley Software Distribution version of the UNIX operating system.
  97.  
  98.  
  99.   2.2.  Basic Printing
  100.  
  101.   By far, the most simplistic way to print in the Linux operating system
  102.   is to send the file to be printed directly to the printing device.
  103.   One way to do this is to use the cat command.  As the root user, one
  104.   could do something like
  105.  
  106.  
  107.  
  108.        # cat thesis.txt > /dev/lp
  109.  
  110.  
  111.  
  112.  
  113.   In this case, /dev/lp is a symbolic link to the actual printing
  114.   device--be it a dot-matrix, laser printer, typesetter, or plotter.
  115.   (See ln(1) for more information on symbolic links.)
  116.  
  117.   For the purpose of security, only the root user and users in the same
  118.   group as the print daemon are able to write directly to the printer.
  119.   This is why commands such as lpr, lprm, and lpq have to be used to
  120.   access the printer.
  121.  
  122.   Because of this, users have to use lpr to print a file.  The lpr
  123.   command is responsible for taking care of all of the initial work
  124.   needed to print the file, and then it hands control over to another
  125.   program, lpd, the line printing daemon.  The line printing daemon then
  126.   tells the printer how to print the file.
  127.  
  128.   When lpr is executed, it first copies the specified file to a certain
  129.   directory (the spool directory) where the file remains until lpd
  130.   prints it.  Once lpd is told that there is a file to print, it will
  131.   spawn a copy of itself (what we programmers call forking).  This copy
  132.   will print our file while the original copy waits for more requests.
  133.   This allows for multiple jobs to be queued at once.
  134.  
  135.   The syntax of lpr(1) is a very familiar one,
  136.  
  137.  
  138.  
  139.        $ lpr [ options ] [ filename ... ]
  140.  
  141.  
  142.  
  143.  
  144.   If a filename is not specified, lpr assumes that the input should come
  145.   from standard input (usually the keyboard, or another program's
  146.   output).  This enables the user to redirect a command's output to the
  147.   printing device.  As such,
  148.  
  149.  
  150.  
  151.        $ cat thesis.txt | lpr
  152.  
  153.  
  154.  
  155.  
  156.   or, something more powerful, like
  157.  
  158.  
  159.  
  160.        $ pr -l60 thesis.txt | lpr
  161.  
  162.  
  163.  
  164.  
  165.   The lpr command accepts several command-line arguments that allow a
  166.   user to control how it works.  Some of the most widely used arguments
  167.   are: -Pprinter specifies the printer to use, -h suppresses printing of
  168.   the burst page, -s creates a symbolic link instead of copying the
  169.   entire file to the spool directory (useful for large files), and -#num
  170.   specifies the number of copies to print.  An example interaction with
  171.   lpr might be something like
  172.  
  173.  
  174.  
  175.        $ lpr -#2 -sP dj thesis.txt
  176.  
  177.  
  178.  
  179.  
  180.   This command would create a symbolic link to the file thesis.txt in
  181.   the spool directory for the printer named dj, where it would be
  182.   processed by lpd.  It would then print a second copy of thesis.txt.
  183.  
  184.   For a listing of all the options that lpr will recognize, see lpr(1).
  185.  
  186.  
  187.   2.3.  Viewing the Print Queue
  188.  
  189.   Sometimes it is useful to know what jobs are currently in a particular
  190.   printer's queue.  This is the sole task of the lpq command.
  191.  
  192.   To see what is in the queue of the default printer (as defined by
  193.   /etc/printcap), use
  194.  
  195.  
  196.  
  197.  
  198.  
  199.   $ lpq
  200.   lp is ready and printing
  201.   Rank   Owner      Job  Files                            Total Size
  202.   active mwf        31   thesis.txt                       682048 bytes
  203.  
  204.  
  205.  
  206.  
  207.  
  208.   2.4.  Canceling a Print Job
  209.  
  210.   Another useful feature of any printing system is the ability to cancel
  211.   a job that has been previously queued.  To do this, use lprm.
  212.  
  213.  
  214.  
  215.        $ lprm -
  216.  
  217.  
  218.  
  219.  
  220.   The above command cancels all of the print jobs that are owned by the
  221.   user who issued the command.  A single print job can be canceled by
  222.   first getting the job number as reported by lpq, and then giving that
  223.   number to lprm.  For example,
  224.  
  225.  
  226.  
  227.        $ lprm 31
  228.  
  229.  
  230.  
  231.  
  232.   would cancel job 31 (thesis.txt) on the default printer.
  233.  
  234.  
  235.   3.  Miscellaneous Items
  236.  
  237.   This section discusses some of the miscellaneous things that you may
  238.   want to know about printing under Linux.
  239.  
  240.  
  241.   3.1.  Formatting
  242.  
  243.   Since most ASCII files are not formatted for printing, it is useful to
  244.   format them in some way before they are actually printed.  This may
  245.   include putting a title and page number on each page, setting the
  246.   margins, double spacing, indenting, or printing a file in multiple
  247.   columns.  A common way to do this is to use a print preprocessor such
  248.   as pr.
  249.  
  250.  
  251.  
  252.        $ pr +4 -d -h"Ph.D. Thesis, 2nd Draft" -l60 thesis.txt | lpr
  253.  
  254.  
  255.  
  256.  
  257.   In the above example, pr would take the file thesis.txt and skip the
  258.   first three pages (+4), set the page length to sixty lines (-l60),
  259.   double space the output (-d), and add the phrase "Ph.D. Thesis, 2nd
  260.   Draft" to the top of each page (-h).  Lpr would then print pr's
  261.   output.  See its on-line manual page for more information on using pr.
  262.  
  263.  
  264.  
  265.   3.2.  The PRINTER Environment Variables
  266.  
  267.   All of the commands in the Linux printing system accept the -P option.
  268.   This option allows the user to specify which printer to use for
  269.   output.  If a user doesn't specify which printer to use, then the
  270.   default printer will be assumed as the output device.
  271.  
  272.   Instead of having to specify a printer to use every time that you
  273.   print, you can set the PRINTER environment variable to the name of the
  274.   printer that you want to use.  This is accomplished in different ways
  275.   for each shell.  For bash you can do this with
  276.  
  277.  
  278.  
  279.        $ PRINTER="printer_name"; export PRINTER
  280.  
  281.  
  282.  
  283.  
  284.   in csh, you can do it with
  285.  
  286.  
  287.  
  288.        % setenv PRINTER "printer_name"
  289.  
  290.  
  291.  
  292.  
  293.   These commands can be placed in your login scripts (.profile or
  294.   .cshrc), or issued on the command-line.  (See bash(1) and csh(1) for
  295.   more information on environment variables.)
  296.  
  297.  
  298.   3.3.  Printing PostScript files
  299.  
  300.   Printing PostScript files on a printer that has a PostScript
  301.   interpreter is simple; just use lpr, and the printer will take care of
  302.   all of the details for you.  For those of us that don't have printers
  303.   with PostScript capabilities, we have to resort to other means.
  304.   Luckily, there are programs available that can make sense of
  305.   PostScript, and translate it into a language that most printers will
  306.   understand.  Probably the most well known of these programs is
  307.   Ghostscript.
  308.  
  309.   Ghostscript's responsibility is to convert all of the descriptions in
  310.   a PostScript file to commands that the printer will understand.  To
  311.   print a PostScript file using Ghostscript, you might do something like
  312.  
  313.  
  314.  
  315.        $ gs -dNOPAUSE -sDEVICE=deskjet -sOutputFile=|lpr thesis.ps
  316.  
  317.  
  318.  
  319.  
  320.   Notice in the above example that we are actually piping the output of
  321.   Ghostscript to the lpr command by using the -sOutputFile option.
  322.  
  323.   Ghostview is an interface to Ghostscript for the X Window System.  It
  324.   allows you to preview a PostScript file before you print it.
  325.   Ghostview and Ghostscript can both be downloaded from
  326.   <ftp://prep.ai.mit.edu/pub/gnu/>.
  327.  
  328.  
  329.  
  330.  
  331.   3.4.  Printing TeX files
  332.  
  333.   One of the easiest ways to print TeX files is to convert them to
  334.   PostScript and then print them using Ghostscript.  To do this, you
  335.   first need to convert them from TeX to a format known as DVI (which
  336.   stands for device-independent).  You can do this with the tex(1)
  337.   command.  Then you need to convert the DVI file to a PostScript file
  338.   using dvips.  All of this would look like the following when typed in.
  339.  
  340.  
  341.  
  342.        $ tex thesis.tex
  343.        $ dvips thesis.dvi
  344.  
  345.  
  346.  
  347.  
  348.   Now you are ready to print the resulting PostScript file as described
  349.   above.
  350.  
  351.  
  352.   3.5.  Printing troff formatted files
  353.  
  354.  
  355.  
  356.  
  357.        $ groff -Tascii thesis.tr | lpr
  358.  
  359.  
  360.  
  361.  
  362.   or, if you prefer,
  363.  
  364.  
  365.  
  366.        $ groff thesis.tr > thesis.ps
  367.  
  368.  
  369.  
  370.  
  371.   and then print the PostScript file as described above.
  372.  
  373.  
  374.   4.  Answers to Frequently Asked Questions
  375.  
  376.  
  377.   Q1.  How do I prevent the staircase effect?
  378.  
  379.   A1.  The staircase effect is caused by the way some printers expect
  380.   lines to be terminated.  Some printers want lines that end with a
  381.   carriage-return/line-feed sequence (DOS-style) instead of the default
  382.   line-feed sequence used for UNIX-type systems.  The easiest way to fix
  383.   this is to see if your printer can switch between the two styles
  384.   somehow---either by flipping a DIP switch, or by sending an escape
  385.   sequence at the start of each print job.  To do the latter, you need
  386.   to create a filter (see Q2 and Foster95b).
  387.  
  388.   A quick fix is to use a filter on the command-line.  An example of
  389.   this might be
  390.  
  391.  
  392.  
  393.        $ cat thesis.txt | todos | lpr
  394.  
  395.  
  396.  
  397.   Q2.  What is a filter?
  398.  
  399.   A2.  A filter is a program that reads from standard input (stdin),
  400.   performs some action on this input, and writes to standard output
  401.   (stdout).  Filters are used for a lot of things, including text
  402.   processing.
  403.  
  404.  
  405.   Q3.  What is a magic filter?
  406.  
  407.   A3.  A magic filter is a filter that performs an action based on a
  408.   file's type.  For example, if the file is a plain, text file, it would
  409.   simply print the file using the normal methods.  If the file is a
  410.   PostScript file, or any other format, it would print it using another
  411.   method (ghostscript).
  412.  
  413.  
  414.   5.  Troubleshooting
  415.  
  416.   This section covers some common things that can go wrong with your
  417.   printing system.  Send suggestions for this section to
  418.   <mwf@engr.uark.edu>.
  419.  
  420.  
  421.   6.  References
  422.  
  423.   This is a section of references on the Linux printing system.  I have
  424.   tried to keep the references section of this HOWTO as focused as
  425.   possible.  If you feel that I have forgotten a significant reference
  426.   work, please do not hesitate to contact me.
  427.  
  428.   Before you post your question to a USENET group, consider the
  429.   following:
  430.  
  431.   o  Is the printer accepting jobs?  (Use lpc(8) to verify.)
  432.  
  433.   o  Is the answer to your question covered in this HOWTO, or the
  434.      Printing Setup HOWTO?
  435.  
  436.   If any of the above are true, you may want to think twice before you
  437.   post your question.  And, when you do finally post to a newsgroup, try
  438.   to include pertinent information.  Try not to just say something like,
  439.   "I'm having trouble with lpr, please help."  These types of posts will
  440.   most definitely be ignored by many.  Also try to include the kernel
  441.   version that you're running, how the error occured, and, if any, the
  442.   specific error message that the system returned.
  443.  
  444.  
  445.      Welsh, Matt.  Linux Installation and Getting Started
  446.         an excellent introductory text for the beginning Linux user
  447.  
  448.  
  449.      Foster, Matt.  Linux Printing Setup HOWTO
  450.         the supplement to this HOWTO; covers topics such as setting up,
  451.         and configuring the print software
  452.  
  453.  
  454.      On-Line Manual Pages
  455.  
  456.      o  cat(1)  concatenate and print files
  457.  
  458.      o  dvips(1)  convert a TeX DVI file to PostScript
  459.  
  460.      o  ghostview(1)  view PostScript documents using Ghostscript
  461.  
  462.  
  463.      o  groff(1)  front-end for the groff document formatting system
  464.  
  465.      o  gs(1)  Ghostscript interpreter/viewer
  466.  
  467.      o  lpc(8)  line printer control program
  468.  
  469.      o  lpd(8)  line printer spooler daemon
  470.  
  471.      o  lpq(1)  spool queue examination program
  472.  
  473.      o  lpr(1)  off-line printer
  474.  
  475.      o  lprm(1)  remove jobs from the line printer spooling queue
  476.  
  477.      o  pr(1)  convert text files for printing
  478.  
  479.      o  tex(1)  text formatting and typesetting
  480.  
  481.  
  482.      USENET newsgroups
  483.  
  484.      o  comp.os.linux.*  a plethora of information on Linux
  485.  
  486.      o  comp.unix.*  discussions relating to the UNIX operating system
  487.  
  488.  
  489.   7.  Colophon
  490.  
  491.   This HOWTO was written using vi, the ultimate editor; the human mind,
  492.   the ultimate computer; and imagination, the ultimate power tool.  The
  493.   computer of choice was a Gateway2000 i486/50 running the Slackware 2.2
  494.   distribution of Linux with version 1.3.4 of the kernel.  The original
  495.   document was written in mark-up format using Linuxdoc-SGML (a hacked
  496.   version of Tom Gordon's QWERTZ DTD).  The HOWTO was then emailed to
  497.   Greg Hankins, the Linux Documentation Project coordinator.  There it
  498.   was converted to PostScript, TeXinfo, DVI, ASCII, and HTML formats.
  499.   Finally it was posted on USENET, and placed in the Linux archives
  500.   found on the SunSITE FTP/WWW servers for easy Internet access.
  501.